{% extends 'layouts/master-page.html' %}
{% block title %}{{ listType }} management{% endblock %}
{% block head %}
<!-- css -->
<link href="/static/css/custom/admin.css" rel="stylesheet" />
<script type="text/javascript" src="/static/js/custom/list.js"></script>
{% endblock %}
{% block content %}
{% include 'subpages/breadcrumbs.html' %}
<!-- Values -->
<input id="values" type="hidden" value="{{listType}}">
<!-- Add new rule -->
<div class="well well-small">
  <table class="table">
    <thead class="thead-dark">
    <tr>
      <th colspan="3">
        {{ listType }} details
      </th>
    </tr>
    </thead>
    <tr>
      <td class="listInput">
        <div class="input-group">
          <form id='addcpe' class="nav form-search" onsubmit="addItem('cpe'); return false;">
            <strong class="form_header">Add an item to the {{ listType }}</strong> <br />
            <input class="form-control" id="cpeid" type="text" placeholder="full or partial CPE" pattern="(cpe:/|cpe:2.3:)[a-z0-9/.:%-_~]+" /> <br />
            <textarea class="form-control" id="cpecomments" rows="4" placeholder="comments, separated by enter"></textarea> <br />
            <input class="btn btn-success btn-sm" id="cpeadd" type="submit" value="Add"/>
          </form>
        </div>
        <a class="btn btn-primary btn-sm" href="{{ url_for('admin.listManagement') }}">Browse...</a>
      </td>
      <td class="listInputCenter">
      <p>or</p>
      </td>
      <td class="listInput">
      <form id='addkeyword' class="nav form-horizontal" onsubmit="addItem('-'); return false;">
        <strong class="form_header">Add CPE keywords to the {{ listType }}</strong> <br />
        <div class="input-group">
          <select class="form-control" id="keywordselect">
            <option value="targetsoftware">Target Software</option>
            <option value="targethardware">Target Hardware</option>
          </select>
          <input id="keywordid" type="text" class="form-control" placeholder="Target Software/Hardware Name">
        </div>
        <textarea class="form-control" id="keywordcomments" rows="4" placeholder="comments, separated by enter"></textarea> <br />
        <input class="btn btn-success btn-sm" id="keywordadd" type="submit" value="Add"/>
      </form>
    </td>
    </tr>
  </table>
</div>
<!-- Current rules -->
{% set rulesList = rules|list %}
<table class="table table-even">
  <thead class="thead-dark">
  <tr class="center_header">
    <th>CPE Rules</th>
    <th>Keywords</th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>
      <table id="cpes" class="table table-hover table-striped">
        <thead class="thead-light">
        <tr>
          <th></th>
          <th>Rule</th>
          <th>Comments</th>
        </tr>
        </thead>
        <tbody>
        {% for ruleID in rulesList if ruleID['type']=='cpe' %}
        <tr>
          <td><a href="javascript:remove('{{ruleID['id']}}')"><i class="far fa-trash-alt"></i></a></td>
          <td>{{ ruleID['id'] }}</td>
          <td>
            <ul>
              {% for comment in ruleID['comments'] %}
              <li>{{ comment }}</li>
              {% endfor %}
            </ul>
          </td>
        </tr>
        {% endfor %}
        </tbody>
      </table>
    </td>
    <td>
      <table id="keywords" class="table table-hover table-striped">
        <thead class="thead-light">
        <tr>
          <th></th>
          <th>Rule</th>
          <th>Keyword</th>
          <th>Comments</th>
        </tr>
        </thead>
        <tbody>
        {% for ruleID in rulesList if ruleID['type']!='cpe' %}
        <tr>
          <td><a href="javascript:remove('{{ruleID['id']}}')"><i class="far fa-trash-alt"></i></a></td>
          <td>{{ ruleID['id'] }}</td>
          <td>
            {% if ruleID['type'] == 'targethardware' %}
            Target Hardware
            {% elif ruleID['type'] == 'targetsoftware' %}
            Target Software
            {% endif %}
          </td>
          <td>
            <ul>
              {% for comment in ruleID['comments'] %}
              <li>{{ comment }}</li>
              {% endfor %}
            </ul>
          </td>
        </tr>
        {% endfor %}
        </tbody>
      </table>
    </td>
  </tr>
  </tbody>




</table>
{% endblock %}
